<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>资源管理</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/qs.js"></script>
    <script src="/axios.min.js"></script>
    <script src="/vue.js"></script>

<body>
<div id="app">
    <table class="table">
        <thead>
        <tr>
            <th>标题</th>
            <th>类别</th>
            <th>文件名称</th>
            <th>时间</th>
            <th>文件链接</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="index in resourceList">
            <td>{{index.title}}</td>
            <td>{{index.type}}</td>
            <td>{{index.fileName}}</td>
            <td>{{new Date(index.create_time).toLocaleDateString()}}</td>
            <td>{{index.fileUrl}}</td>
            <!--<td><a target="ges" href=`/updateNew.html${index.resourceId}`>更新资源</a></td>-->
            <td>
                <a target="ges" @click="copyFileUrl(index.fileUrl)" href="JavaScript:void(0)">复制链接</a> |
                <a target="ges" @click="deleteResource(index.resource_id,index.fileUrl)" href="javaScript:void(0)">删除资源</a> &nbsp;| &nbsp;
                <a target="ges" @click="openfile(index.fileUrl)" href="JavaScript:void(0)">预览</a>
            </td>
        </tr>
        </tbody>
    </table>
</div>
</body>
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                resourceList:[]
            }
        },
        methods: {
            openfile(val){
                window.open(`https://view.officeapps.live.com/op/view.aspx?src=${val}`)
            },
            deleteResource(resource_id,fileUrl){
                let str = "http://gxsec.org.cn/staticFile/file/".length
                let fileName = fileUrl.substring(str,str.length)
                window.location.href = `deleteResource?resourceId=${resource_id}&fileName=${fileName}`
            },
            copyFileUrl(Url2){
                var oInput = document.createElement('input');
                oInput.value = Url2;
                document.body.appendChild(oInput);
                oInput.select(); // 选择对象
                document.execCommand("Copy"); // 执行浏览器复制命令
                oInput.className = 'oInput';
                oInput.style.display='none';
                alert('复制成功');
            }
        },
        created(){
            axios.get("/getAllResource").then(res=>{
                if(res.data){
                    this.resourceList = res.data
                }
            })
        }
    })
</script>
</html>